'use strict';

const path = require('path');
const _ = require('lodash');

const NODE_ENV = process.env.NODE_ENV || 'development';
const root = path.resolve(__dirname, '..');

const baseConfig = {
  app: {
    name: 'fin_koa_credit',
    root: root,
    env: NODE_ENV,
    isDev: NODE_ENV === 'development',
    isProd: NODE_ENV === 'production',
    secret: process.env.SECRET || 'my&&&&&&secret!',
    limit: 50,
    upload: process.env.UPLOAD || path.resolve(root, 'upload'),
    worker: {
      numCPUs: 1,
      limit: 20
    },
    log: {
      dir: process.env.LOG_DIR || path.resolve(root, 'log'),
      level: process.env.LOG_LEVEL || 'info'
    }
  }
};

const platformConfig = {
  development: {
    app: {
      port: 3009,
      cacheTime: 24 * 60 * 60 * 1000
    },
    mongo: {
      uri: process.env.MONGO_URI_DEV || 'mongodb://localhost:27017/test'
    }
  },
  test: {
    app: {
      port: 3010
    },
    mongo: {
      uri: process.env.MONGO_URI_TEST || 'mongodb://localhost:27017/test'
    }
  },
  production: {
    app: {
      port: process.env.PORT || 3011,
      cacheTime: 7 * 24 * 60 * 60 * 1000
    },
    mongo: {
      uri: process.env.MONGO_URI || 'mongodb://localhost:27017/test'
    }
  }
};

module.exports = _.merge(baseConfig, platformConfig[NODE_ENV]);
